/*
 * MenuConnexion.java
 * 
 * Created on 2 janv. 2008, 11:00:49
 * 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package Risk.IHM;

import java.awt.BorderLayout;
import java.awt.GridLayout;
import java.awt.Image;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;

import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JSplitPane;

/**
 * Construction du menu de connexion
 * @author nicoleta
 *
 */
public class MenuConnexion extends JFrame implements ActionListener, WindowListener {
	private static final long serialVersionUID = 1L;
	/**
	 * bouton NouvPartie : permet de demarrer une nouvelle partie, actif quand on lance le programme
	 * et inactif quand on accede au menu a partir du plateau de jeu 
	 * 
	 * boutons Charger, Sauver, Aide, Quitter : actifs dans tous les cas
	 * 
	 * bouton StartServ : actif quand on lance le programme et inactif une fois qu'on a commence une 
	 * partie et donc le serveur est demarre 
	 * 
	 */
	private JButton jbNouvPartie, jbCharger, jbSauver, jbAide, jbQuitter, jbStartServ;
	private boolean etatBoutons = true; 
	private static int nbOccurences = 0;
	
	public MenuConnexion(boolean etat) {
		super(" Connexion ...");
		this.etatBoutons = etat;
		nbOccurences++;
		initComponents(this);
		//this.setSize(430,250);
                this.pack();
		this.setLocation(50, 50);
		this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		this.setVisible(true);	
	}
	private void initComponents(JFrame f) {
		/* panel qui contient les boutons principaux */
		JPanel jpBoutons = new JPanel(new GridLayout(5,1));
		JPanel jpImage = new JPanel(new BorderLayout());
                /* image de l'icone du jeu */
                ImageIcon imgIc = new ImageIcon("Images/Jeu1.jpg");
               
                JLabel jlImage = new JLabel(imgIc);
		jpImage.add(jlImage,BorderLayout.CENTER);
                
		jbNouvPartie = new JButton(" * Nouvelle partie * ");
                jbNouvPartie.addActionListener(this);
		jbCharger = new JButton(" * Charger... *");
                jbCharger.addActionListener(this);
		jbSauver = new JButton(" * Sauver ... *");
                jbSauver.setEnabled(false);
                jbSauver.addActionListener(this);
		jbAide = new JButton(" * Aide *");
                jbAide.addActionListener(this);
		jbQuitter = new JButton(" * Quitter *");
                jbQuitter.addActionListener(this);
		jpBoutons.add(jbNouvPartie);
		jpBoutons.add(jbCharger);
		jpBoutons.add(jbSauver);
		jpBoutons.add(jbAide);
		jpBoutons.add(jbQuitter);
		JSplitPane jsp = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT,jpImage,jpBoutons);
		f.add(jsp, BorderLayout.CENTER);
		
                
                /* bouton pour demarrer le serveur */
		jbStartServ = new JButton(" START SERVEUR ");
		f.add(jbStartServ, BorderLayout.SOUTH);		
	}
        /**
         * méthode qui fait le test sur les boutons 
         */
        @Override
	public boolean isActive() {
		if(nbOccurences != 0) {
			jbStartServ.setEnabled(false);
                        jbSauver.setEnabled(true);
			return true;
		}
		else return false;
	}

    public void actionPerformed(ActionEvent e) {
        Object o = (Object)e.getSource();
        if(o.equals(jbQuitter)) {
            this.addWindowListener (new WindowAdapter(){
                @Override
			public void windowClosing (WindowEvent e){
				System.exit(0);
			}
            });
        }
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public void windowOpened(WindowEvent e) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public void windowClosing(WindowEvent e) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public void windowClosed(WindowEvent e) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public void windowIconified(WindowEvent e) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public void windowDeiconified(WindowEvent e) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public void windowActivated(WindowEvent e) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public void windowDeactivated(WindowEvent e) {
        throw new UnsupportedOperationException("Not supported yet.");
    }
}